package com.ca.ridersclubapplication.data.view;

import android.view.View;

import com.ca.ridersclubapplication.data.DataHandler;
import com.ca.ridersclubapplication.data.entity.BooleanEntity;
import com.ca.ridersclubapplication.data.entity.Handleable;
import com.ca.ridersclubapplication.view.CallbackView;
import com.ca.ridersclubapplication.view.card.MiniInfoCard;
import com.ca.ridersclubapplication.view.list.FollowMiniClubListView;

public class FollowMiniClubListCallbackView implements CallbackView {

    private final FollowMiniClubListView view;

    public FollowMiniClubListCallbackView(FollowMiniClubListView view) {
        this.view = view;
    }

    @Override
    public void update() {
        //  获取数据
        Handleable data = DataHandler.getData("Login");
        if (view != null && data instanceof BooleanEntity) {
            boolean isLogin = ((BooleanEntity) data).getValue();
            if (!isLogin) {
                view.gotoLoginButton.setVisibility(View.VISIBLE);
                view.gotoLoginButton.setEnabled(true);
                view.emptyView.setVisibility(View.GONE);
                for (MiniInfoCard card : view.getCardList()) {
                    card.setVisibility(View.GONE);
                }
            }
            else {
                view.gotoLoginButton.setVisibility(View.GONE);
                view.gotoLoginButton.setEnabled(false);
                view.flush();
            }
        }
    }
}
